﻿using D2_Binding.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml;

namespace D2_Binding
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            int[][] nums =
            {
                new int[9]{ 0,1,7,  0,0,2,  0,0,3 },
                new int[9]{ 8,0,0,  0,0,0,  5,0,7 },
                new int[9]{ 0,0,4,  3,7,0,  0,8,0 },

                new int[9]{ 0,0,0,  7,4,0,  0,0,5 },
                new int[9]{ 7,2,0,  0,9,0,  4,0,0 },
                new int[9]{ 3,0,0,  5,0,0,  0,6,0 },

                new int[9]{ 4,3,8,  0,0,1,  0,0,0 },
                new int[9]{ 0,0,0,  0,0,7,  8,1,0 },
                new int[9]{ 0,0,6,  2,0,4,  0,5,0 }
            };
            int i = 4;
            int[] nine = nums.Where((_, index) => index >= i / 3 * 3 && index <= i / 3 * 3 + 2) // 选择这个九宫的三行
                 .SelectMany((row) => row.Skip(i % 3 * 3).Take(3)).ToArray(); // 从三行中选择九宫中的数字

            int[] a = new int[] { 0, 1, 2, 3 };
            int[] b = new int[] { 2, 3, 4 };
            var r = a.Except(b).ToList();
        }



    }

    public class Human
    {
        public Human(bool a, int b)
        {
            a = !a;
            b++;
        }

        public Human(int n) : this(true, n)
        {
            n *= -1;
        }
    }

    public class LogonMultiBindingConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (!values.Cast<string>().Any(text => string.IsNullOrEmpty(text))
                && values[0].ToString() == values[1].ToString()
                && values[2].ToString() == values[3].ToString())
            {
                return true;
            }
            return false;
        }

        // 不会被调用
        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }



    public class StateToNullableBoolConverter : IValueConverter
    {
        // 将 State 转换为 bool?
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            State s = (State)value;
            switch (s)
            {
                case State.Available:
                    return true;
                case State.Locked:
                    return false;
                case State.Unknown:
                default:
                    return null;
            }
        }

        // 将 bool? 转换为 State
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool? nb = (bool?)value;
            switch (nb)
            {
                case true:
                    return State.Available;
                case false:
                    return State.Locked;
                case null:
                default:
                    return State.Unknown;
            }
        }
    }

    public enum Category
    {
        Bomber,
        Fighter,
    }
    public enum State
    {
        Available,
        Locked,
        Unknown,
    }

    public class Plane
    {
        public Category Category { get; set; }
        public string Name { get; set; }
        public State State { get; set; }
    }

    class Student
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public int Age { get; set; }
    }
}
